#include "w_directshow.h"
HRESULT EnumerateDevices(REFGUID category, IEnumMoniker **ppEnum) {
    ICreateDevEnum *pDevEnum;
    HRESULT hr = CoCreateInstance(CLSID_SystemDeviceEnum, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&pDevEnum));
    if (SUCCEEDED(hr)) {
        hr = pDevEnum->CreateClassEnumerator(category, ppEnum, 0);
        if (hr == S_FALSE) {
            hr = VFW_E_NOT_FOUND;
        }
        pDevEnum->Release();
    }
    return hr;
}
HRESULT SelectedDevices(REFGUID category, ULONG nIndex, IMoniker **ppMoniker) {
    IEnumMoniker *pEnumMoniker;
    HRESULT hr = EnumerateDevices(category, &pEnumMoniker);
    if (SUCCEEDED(hr)) {
        pEnumMoniker->Skip(nIndex);
        hr = pEnumMoniker->Next(1, ppMoniker, NULL);
        pEnumMoniker->Release();
    }
    return hr;
}